/**
 * @author antonio081014
 * @since Nov 29, 2011, 4:23:01 AM
 */
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;

public class DropCoins {

    public int getMinimum(String[] board, int K) {
	int N = board.length;
	int M = board[0].length();
	int ret = Integer.MAX_VALUE;
	for (int x = 0; x < N; x++) {
	    for (int y = 0; y < M; y++) {
		for (int xx = x + 1; xx <= N; xx++) {
		    for (int yy = y + 1; yy <= M; yy++) {
			int count = 0;
			for (int i = x; i < xx; i++) {
			    for (int j = y; j < yy; j++) {
				if (board[i].charAt(j) == 'o')
				    count++;
			    }
			}
			if (count == K) {
			    int sum = 2 * Math.min(x, N - xx)
				    + Math.max(x, N - xx) + 2
				    * Math.min(y, M - yy) + Math.max(y, M - yy);
			    ret = Math.min(ret, sum);
			}

		    }
		}
	    }
	}
	if (ret == Integer.MAX_VALUE)
	    return -1;
	return ret;
    }
    // <%:testing-code%>
}
// Powered by [KawigiEdit] 2.0!
